// DONT USE : tuning in progress

// attention sous FireFox :
//   le traitt des evts est attach? au document 
//   on s'interesse donc ? l'attribut target pour savoir si l 'evt doit ?tre trait? 
//    --> il faut que le flag dragAndDrop soit positionn? sur les elts div html "en surface" seuls d?sign?s par l'attribut target
// reste a voir:
//  - DD avec cible(s) n'ayant pas le meme pere
//  - purge du code
//  - prise en compte du ReSize concurrent avec le DD sur 1 mme Div (cf. curseurs)
//  - apparence des curseurs a revoir en partioculier avec IE
//  - pb de zindex ; solution si il y a un fantome , il devrait etre rattach? ? document
//  - pb persistance DD si passage sur ascenceur et sortie du document (cas ou la div avec ascenceurs est siru?e ? l'extreme droite (tjrs 1 pb l extreme droite !))
//  - ajout d'1 image ? la place du curseur lors du DD
//  l evt mouse down pourrait sans doute ne pas etre rattache au document
var ENREG_DD = 99;           // niveau de trace du DD = 99

//en fait inutilisable (surtout ave la version 4.1 de Moz) :
//var HDL_EVT_COMM = true;     // meme technique d'enreg des comportement pour IE et W3C (pas d'utilisation de addEventListener pour W3C)

var oDeplact= null;    // ? incorporer ds drag&drop ?

var _ECN_ICONE_DD_DEF = 'icone_DD_def';
var SENSITIVEEDGEWIDTH_DEFAULT = 0;


rialto.widgetBehavior.DDStdtLoadLimitsMoving 
= function () {
//==========================================
// limites right-bottom du deplact fct? des dim d'un elt Html (en g?n?ral du parent) au moment du MouseDown
// les limites font parties des specs de cr?ation de l'objet ayant le comportement RS
  // il faut juste r??valuer leurs valeurs
/* traceExec('DDStdtLoadLimitsMoving begin',1); */
/* traceExec('------- DDStdtLoadLimitsMoving bRectLim = '+this.movingLimits.bRectLim,73); */

  if (this.movingLimits.bRectLim) {
    this.movingLimits.rectLim.bottom      = eval(this.movingLimits.rectLim.bottomSpecs);
    this.movingLimits.rectLim.right       = eval(this.movingLimits.rectLim.rightSpecs);
    this.movingLimits.rectLim.top         = eval(this.movingLimits.rectLim.topSpecs);
    this.movingLimits.rectLim.left        = eval(this.movingLimits.rectLim.leftSpecs);
    
  }
    if (this.specs.ghost) { 
         this.specs.ghost.top    = eval(this.specs.ghost.topSpec);
         this.specs.ghost.height = eval(this.specs.ghost.heightSpec);
         //to revise : why not width ?
    }


/*
// version coord absolues :
// traceExec('bDynamicsMovingLimits',5); 
  if (this.movingLimits.bRectLim) {
   // one oHtml (+ deltas adjustements) get the reference's limits 
   if (this.movingLimits.bRefDiv) {
// traceExec('bDynamicsMovingLimits  bRecDiv',5); 
    this.movingLimits.rectLim.top         = _rum.$posInViewPort(this.movingLimits.refDiv).top;
    										+ eval(this.movingLimits.rectLim.dTop);
    this.movingLimits.rectLim.left        = _rum.$posInViewPort(this.movingLimits.refDiv).left;
    										+ eval(this.movingLimits.rectLim.dLeft);
    //alert('this.movingLimits.refDiv= '+this.movingLimits.refDiv.id);
    this.movingLimits.rectLim.bottom      =    parseInt(this.movingLimits.rectLim.top)
    										+  this.movingLimits.refDiv.offsetHeight
    										+  eval(this.movingLimits.rectLim.dBottom);
    this.movingLimits.rectLim.right       =    parseInt(this.movingLimits.rectLim.left)
    										+  this.movingLimits.refDiv.offsetWidth
    										+  eval(this.movingLimits.rectLim.dRight);
   }
   else {  //case : each limit (in absolute coord) is an expression to evaluate at mouse down
// traceExec('bDynamicsMovingLimits no bRectDiv',5); 
    this.movingLimits.rectLim.top         = eval(this.movingLimits.rectLim.topSpecs);
    this.movingLimits.rectLim.left        = eval(this.movingLimits.rectLim.leftSpecs);
    this.movingLimits.rectLim.bottom      = eval(this.movingLimits.rectLim.bottomSpecs);
    this.movingLimits.rectLim.right       = eval(this.movingLimits.rectLim.rightSpecs);
   }
  }
    
 // to revise :   
    if (this.specs.ghost) { 
         this.specs.ghost.top    = eval(this.specs.ghost.topSpec);
         this.specs.ghost.height = eval(this.specs.ghost.heightSpec);
         //to revise : why not width ?
    }

*/

 traceExec('loadDyn Specs  top= '+this.movingLimits.rectLim.topSpecs
+ ' left= '+this.movingLimits.rectLim.leftSpecs
+ ' right= '+this.movingLimits.rectLim.rightSpecs
+ ' bottom= '+this.movingLimits.rectLim.bottomSpecs
,1);
  
traceExec('loadDyn top= '+this.movingLimits.rectLim.top 
+ ' left= '+this.movingLimits.rectLim.left
+ ' right= '+this.movingLimits.rectLim.right
+ ' bottom= '+this.movingLimits.rectLim.bottom
,1);

/* traceExec('DDStdtLoadLimitsMoving end',1); */
}

rialto.widgetBehavior.DDStdtLoadParameters 
= function (specs) {
//========================================
// @param #0 specs =
//    {  mobilite    : DragAndDrop / ReSize,      mobility type
//
//		@param #1  oHtmlEvtTarget: 	[array of ] Html object 	who capture Drag event
//		@param #2  oHtmlToMove	:	Html object 				to move by drag and drop
//		@param #3  dragMood		:	'directMove '||'ghostMove'	with[out] ghost of object to move
//		@param #4  bSelectMark	:	boolean						with mark of select-state
//		@param #5  bDynamicsMovingLimits  : boolean				compute limits of move only in mouse down
//		@param #6  ghost		:								define aspect of ghost to move
//			@param #61  aspect	:	'frame' || 'rect' || 'icon'	
//				@param #62	top		:  force top ; used for ex. in grid 
//				@param #63	height	:  fixe height if hight must be diff. of oHtmlToMove height; used for ex. in grid 
//			@param #64	bOnePixel:  boolean						use for authorisation of drop
//			@param #65 asChild : apend ghost as child of oHtmlToMove.parentNode and not direct in ViewPort																cursor position = reference for compute position of moving 
//                                                              object to drop / target
//		@param #7  bMUpAction	:	boolean						callback (or not) this.synchroDDMup at mouseUp time
//		@param #8  posRelI										initial position of draggable object
//			@param #81  top										(used for Cursor widget)
//			@param #82  left
//		@param #9  modCurs	naming to revise					modify cursor aspect / event
//			@param #91	 avantDD
//			@param #92   avantClic
//		@param #10 magneticsGrid								limit move to a grid
//			@param #111 widthCol
//			@param #112 heightRow
//		@param #11 complementProp								used for Cursor widget
//		@param #12 movingLimits									limit movement
//			@param #121	 bCircular   							(used for Cursor widget) 
//			@param #122  orientation : 'v' || 'h' | '2D'     	move orientation limits : vertical, horizontal, 2D
//			@param #123	 rectLim {top, left, bottom, right }	rectangle limits (dim relative to parent)
//			@param #124  oHtmlRef								obj Html's ref for boundaries; default = parent(oHtmlToMove)
//		@param #13 isWithLimitsDisplayed						visible witness of limits
//		@param #14 isWithMovingInfo 							display info of moving (top,left, deltas)
//		@param #15 isWithMovingInfoInRel 						display info of moving (top,left, deltas) in parent
//		@param #16 sensitiveEdgeWidth : <nb pixel>		  		width of non margin for DD (cf ReSize simultaneous)

if (! specs)
  specs = new Object;
  
this.specs = new Object;
/* traceExec('-------DDStdtLoadParameters  bRectLim = '+specs.bRectLim,73); */

/*-------------------------------
*  parameter # 1 : oHtmlEvtTarget 
*
*  array of DD-event Html targets  : defaut target = this
-------------------------------*/
 if (!specs.oHtmlEvtTarget){
   this.specs.oHtmlEvtTarget = new Array;
   this.specs.oHtmlEvtTarget[0] = this;
 }
 else
 if (! (specs.oHtmlEvtTarget instanceof Array)){
   var woHtmlEvtTarget = specs.oHtmlEvtTarget;
   this.specs.oHtmlEvtTarget = new Array;
   this.specs.oHtmlEvtTarget[0] = woHtmlEvtTarget;
 }
 else
 if (specs.oHtmlEvtTarget instanceof Array){
   this.specs.oHtmlEvtTarget = specs.oHtmlEvtTarget;
 }
 else{
   /* traceExec('pb def cible DD',1); */
 }

// a voir eventuellement --- limitations internes aux cibles potentielles (notion de marge)
// for (var i=0; i <this.specs.oHtmlEvtTarget; i++){
//  if (this.specs.oHtmlEvtTarget[i].exclusionMarge)
//  ...
//}

/*-------------------------------
*  parameter # 2 : oHtmlToMove 
*
*  object Html to Drag; default = this
-------------------------------*/
 this.specs.oHtmlToMove = specs.oHtmlToMove ?  specs.oHtmlToMove : this;
 /* traceExec('DD specs : oHtmlToMove.id = '+ this.specs.oHtmlToMove.id,1); */
 
/*-------------------------------
*  parameter # 3 : dragMood
*
*  drag mood : 'directMove' or 'Move' ; default = 'directMove'
-------------------------------*/
//--- direct move of object (objetEnDeplact) while mouse move
// (only for the direct action = move , may be others actions  cf..synchro)
/* if (   (!specs.dragMood)      // facilite si type ghost defini --> dragMood de type ghost
     && (specs.ghost))
     specs.dragMood = 'ghostMove';
*/
this.specs.dragMood    = (specs.dragMood != null)    ?  specs.dragMood         
                                                     : specs.ghost ? 'ghostMove'
                                                     			   :'directMove';
/* traceExec('DD specs : dragMood = \''+ this.specs.dragMood+'\'',1); */
                                                                   
/*-------------------------------
*  parameter # 4 : bSelectMark
*
*  mark object to move as selected ; default = true if ghost, false else
-------------------------------*/
this.specs.bSelectMark    = (specs.bSelectMark != null)   ?  specs.bSelectMark         
                                                         : true;
/* traceExec('DD specs : bSelectMark = '+ this.specs.bSelectMark,1); */

/*-------------------------------
*  parameter # 5 : bDynamicsMovingLimits 
*
* compute limits of move at mouse down event time; default : true
-------------------------------*/
this.specs.bDynamicsMovingLimits = (specs.bDynamicsMovingLimits != null)    
 									?  specs.bDynamicsMovingLimits  : true;
/* traceExec('DD specs : bDynamicsMovingLimits  = '+ this.specs.bDynamicsMovingLimits ,1); */

/*-------------------------------
*  parameter # 6 : ghost
*
*  object to store ghost specifications 
*		default : {aspect: 'frame', top:0, height: <height of oHtmlToMove>, bOnePixel: true)
-------------------------------*/
this.specs.ghost = new Object;
if (this.specs.dragMood == 'ghostMove') {
	if  (specs.ghost) {
		traceExec('avant this.specs.oHtmlToMove'+_rum.$getHeight(this.specs.oHtmlToMove),2);
	     this.specs.ghost.height = specs.ghost.height ? specs.ghost.height
	                                                  //: pixHeight(this.specs.oHtmlToMove,true)
	                                                  : '_rum.$getHeight(this.specs.oHtmlToMove)';
	                                                  //: '_rum.$getHeight(oHtmlToMove)';
	
	     this.specs.ghost.top    = specs.ghost.top    ? specs.ghost.top 
	                                                      : 0; 

	     this.specs.ghost.asChild    = specs.ghost.asChild  ? specs.ghost.asChild
	                                                      	: false; 
		/**/
		/* traceExec('this.specs.ghost.aspect = '+this.specs.ghost.aspect,2); */
	     this.specs.ghost.aspect = specs.ghost.aspect || 'cadre';
	     if (       (this.specs.ghost.aspect != 'frame')
	         &&     (this.specs.ghost.aspect != 'rect')) {
	         this.specs.ghost.bIcone = true;
	         if (this.specs.ghost.aspect == 'icon') {
	            this.specs.ghost.aspect = _ECN_ICONE_DD_DEF
	         }
	     }
	     if (specs.ghost.bOnePixel)
	          this.specs.ghost.bOnePixel = specs.ghost.bOnePixel;
	     else {
	          this.specs.ghost.bOnePixel = this.specs.ghost.bIcone ? true : false;
	          
	     }
	}
	else {
	      this.specs.ghost.aspect    = 'frame';
			//useless ?	      
		  this.specs.ghost.top       = 0; 
			//useless ?	      
		  this.specs.ghost.height    = '_rum.$getHeight(this.specs.oHtmlToMove)';
	                                   //  '_rum.$getHeight(oHtmlToMove)';
		  //pixHeight(this.specs.oHtmlToMove,true); 
	      this.specs.ghost.bOnePixel = false;
	}
	/* traceExec('DD specs : ghost = '+this.specs.ghost,1); */	
	/* traceExec('DD specs : ghost.aspect = \'' + this.specs.ghost.aspect+'\'',1); */
	/* traceExec('DD specs : ghost.top = ' + this.specs.ghost.top ,14); */
	/* traceExec('DD specs : ghost.height = ' + this.specs.ghost.height,14); */
	/* traceExec('DD specs : ghost.bOnePixel = ' + this.specs.ghost.bOnePixel,1); */
  
}
// no ghost; move directly the object Html to drag
else {
      this.specs.ghost 		 = false;
      this.specs.bSelectMark = false;
}

if  (this.specs.bDynamicsMovingLimits) {
   this.specs.ghost.heightSpec  = this.specs.ghost.height;
   this.specs.ghost.topSpec 	= this.specs.ghost.top;
}
else {
   this.specs.ghost.height  = eval(this.specs.ghost.height);
   this.specs.ghost.top 	= eval(this.specs.ghost.top);
}

/*-------------------------------
*  parameter # 7 : bMUpAction
*
*  call (or not) this.synchroDDMup at the time of mouseUp;   default : true	
-------------------------------*/
this.specs.bMUpAction    = (specs.bMUpAction != null)    ?  specs.bMUpAction  : true;
/* traceExec('DD specs : bMUpAction = '+this.specs.bMUpAction,1); */

/*-------------------------------
*  parameter # 8 : posRelI
*
* object to store initial top and left of object to move ; default = null
-------------------------------*/
  this.specs.posRelI = new Object;
  if ( specs.posRelI){
    this.specs.posRelI.top       = specs.posRelI.top ;
    this.specs.posRelI.left      = specs.posRelI.left;
/* traceExec('DD specs : posRelI.top = '+this.specs.posRelI.top,1); */
/* traceExec('DD specs : posRelI.left = '+this.specs.posRelI.left,1); */
  }

/*-------------------------------
*  parameter # 9 (to revise) : modCurs
*
*  object to store cursor specifications ; default : {
-------------------------------*/
//--- modif apparence du curseur
  this.specs.modCurs = new Object;
  if (specs.modCursor){
    this.specs.modCurs.avantDD   = (specs.modCursor.avantDD != 'undefined')   ? specs.modCursor.avantDD    : true;
    this.specs.modCurs.auClic = (specs.modCursor.auClic != 'undefined') ? specs.modCursor.auClic  : true;
  }
  else {
    this.specs.modCurs.avantDD   = true;
    this.specs.modCurs.auClic = true;
  }

/*-------------------------------
*  parameter # 10 : magneticsGrid
*
*  define grid (width between columns , height between rows)
*  to limit possible positions to drop  ; default : null
-------------------------------*/
   if (specs.magneticsGrid){
      this.specs.magneticsGrid = new Object;
      this.specs.magneticsGrid.widthCol = specs.magneticsGrid.widthCol  || 10;
      this.specs.magneticsGrid.heightRow = specs.magneticsGrid.heightRow || 10;
/* traceExec('DD specs : magnet.widthCol = '+this.specs.magneticsGrid.widthCol,1); */
/* traceExec('DD specs : magnet.heightRow = '+this.specs.magneticsGrid.heightRow,1); */
   }
/* traceExec('DD specs : magneticsGrid = '+this.specs.magneticsGrid,1); */

/*-------------------------------
*  parameter # 11 : complementProp
*
*  for widget Cursor
-------------------------------*/
this.complementProp = specs.complementProp;
/* traceExec('DD specs : complementProp = '+this.specs.complementProp,1); */

/*-------------------------------
*  parameter # 12,13 : movingLimits, isWithLimitsDisplayed
*
*  object to define limits of move
*		default : {bRectLim = true, bCircular = false, orientation = '2D',
*                  rectLim : { top : 0 , left : 0, right : <parent width> , bottom : <parent height>)}
-------------------------------*/
if (!specs.movingLimits)
	specs.movingLimits = {};
	
this.movingLimits = new Object;
this.movingLimits.bCircular  	= specs.movingLimits.bCircular || false;
this.movingLimits.orientation  	= specs.movingLimits.orientation ? specs.movingLimits.orientation : '2D';
traceExec('specs.bRectLim avant affact de this.movingLimits.bRectLim = '+
specs.bRectLim,73);
this.movingLimits.bRectLim = (specs.bRectLim != null) ? specs.bRectLim :  true;
/* traceExec('later this.movingLimits.bRectLim = '+this.movingLimits.bRectLim,73); */
/* traceExec('specs.movingLimits.rectLim = '+specs.movingLimits.rectLim,73); */
this.movingLimits.rectLim = new Object;
var flagModSpecsMovingLimitsRectLim = false;
if (!specs.movingLimits.rectLim) {
 	specs.movingLimits.rectLim = {};
	flagModSpecsMovingLimitsRectLim = true;
}
else {

	for (var i in specs.movingLimits.rectLim) {
		/* traceExec('['+i+']= '+specs.movingLimits.rectLim[i],73); */
	}
	/* traceExec('rectLim -> bRectLim = true',73); */
//	/* traceExec('specs.movingLimits.rectLim.length = '+specs.movingLimits.rectLim[].length,73); */
    this.movingLimits.bRectLim = true;
}
/* traceExec('later 1 this.movingLimits.bRectLim = '+this.movingLimits.bRectLim,73); */

this.movingLimits.oHtmlRef = specs.movingLimits.oHtmlRef || this.specs.oHtmlToMove.parentNode;
//alert('this.specs.oHtmlToMove= '+this.specs.oHtmlToMove);
/* traceExec('this.movingLimits.oHtmlRef= '+this.movingLimits.oHtmlRef.id,2); */

if (this.movingLimits.bRectLim)
    this.movingLimits.isWithLimitsDisplayed = true;  //default
else
 	this.movingLimits.isWithLimitsDisplayed = false;  //default

if (specs.magneticsGrid){
	this.movingLimits.isWithLimitsDisplayed = true;  //default
	this.specs.magneticsGrid.bDisplayed = true;	
}
if (specs.isWithLimitsDisplayed != undefined)	
	this.movingLimits.isWithLimitsDisplayed = specs.isWithLimitsDisplayed; //specs


// horizontal move authorized
//if    (   (this.movingLimits.orientation == 'h')
//         ||(this.movingLimits.orientation == '2D')){
   // limits fixed in instanciation of DD behavior
   if  (!this.specs.bDynamicsMovingLimits) {
   /* traceExec('specs.movingLimits.rectLim= '+specs.movingLimits.rectLim,1); */
     this.movingLimits.rectLim.right =   eval(specs.movingLimits.rectLim.right) 
                                      || _rum.$getWidth ( this.movingLimits.oHtmlRef,borderLess=true);
//                                      || _rum.$getWidth ( this.specs.oHtmlToMove.parentNode,borderLess=true);
     this.movingLimits.rectLim.left        =  eval(specs.movingLimits.rectLim.left)       || 0;
     
   }
	// limits computed on DD mouseDown  
   else {
     this.movingLimits.rectLim.rightSpecs = specs.movingLimits.rectLim.right 
//                                || '_rum.$getWidth ( this.specs.oHtmlToMove.parentNode,borderLess=true)';
                                      || '_rum.$getWidth ( this.movingLimits.oHtmlRef,borderLess=true)';
   }
// }

// vertical move authorized
// if    (   (this.movingLimits.orientation == 'v')
//          ||(this.movingLimits.orientation == '2D')){
   // limits fixed in instanciation of DD behavior
   if (!this.specs.bDynamicsMovingLimits) {
     this.movingLimits.rectLim.bottom = eval(specs.movingLimits.rectLim.bottom) 
//                                    || _rum.$getHeight(this.specs.oHtmlToMove.parentNode,borderLess=true);
                                    || _rum.$getHeight(this.movingLimits.oHtmlRef,borderLess=true);
                                   
     this.movingLimits.rectLim.top    = eval(specs.movingLimits.rectLim.top)    || 0;
   }
	// limits computed on DD mouseDown  
   else{
     this.movingLimits.rectLim.bottomSpecs = specs.movingLimits.rectLim.bottom 
//                               || '_rum.$getHeight(this.specs.oHtmlToMove.parentNode,borderLess=true)';
                                    || '_rum.$getHeight(this.movingLimits.oHtmlRef,borderLess=true)';
     this.movingLimits.rectLim.leftSpecs  = specs.movingLimits.rectLim.left  || 0;
     this.movingLimits.rectLim.topSpecs    = specs.movingLimits.rectLim.top    || 0;
   }
// }

/*-------------------------------
*  parameter # 14 : isWithMovingInfo
*
*  display or not info / moving : (absTop, absLeft (totalTopMovement, total left movement))
*		default : false 
-------------------------------*/
this.isWithMovingInfo = (specs.isWithMovingInfo != undefined) ? specs.isWithMovingInfo :  false;

/*-------------------------------
*  parameter # 15 : isWithMovingInParentInfo
*
*  display info of  moving in parent or in viewPort: (absTop, absLeft (totalTopMovement, total left movement))
*		default : false -> measures in viewPort 
-------------------------------*/
/* traceExec('isWithMovingInParentInfo= '+specs.isWithMovingInParentInfo,2); */
this.isWithMovingInParentInfo = (specs.isWithMovingInParentInfo != undefined) ? specs.isWithMovingInParentInfo :  false;
if (specs.isWithMovingInParentInfo != undefined)
	this.isWithMovingInfo = true;
/* traceExec('isWithMovingInParentInfo= '+this.isWithMovingInParentInfo,2); */
	
/* traceExec('DD specs : movingLimits = '+this.movingLimits,1); */

if (this.movingLimits) {
	/* traceExec('DD specs : movingLimits.orientation = \''+this.movingLimits.orientation+'\'',1); */
	/* traceExec('DD specs : movingLimits.bCircular = '+this.movingLimits.bCircular,1); */
	/* traceExec('DD specs : movingLimits.bRectLim = '+this.movingLimits.bRectLim,1); */
	if (this.movingLimits.rectLim) {
		/* traceExec('DD specs : movingLimits.rectLim.top = '+this.movingLimits.rectLim.top,1); */
		/* traceExec('DD specs : movingLimits.rectLim.topSpecs = '+this.movingLimits.rectLim.topSpecs,1); */
		/* traceExec('DD specs : movingLimits.rectLim.bottom = '+this.movingLimits.rectLim.bottom,1); */
		/* traceExec('DD specs : movingLimits.rectLim.bottomSpecs = '+this.movingLimits.rectLim.bottomSpecs,1); */
		/* traceExec('DD specs : movingLimits.rectLim.right = '+this.movingLimits.rectLim.right,1); */
		/* traceExec('DD specs : movingLimits.rectLim.rightSpecs = '+this.movingLimits.rectLim.rightSpecs,1); */
		/* traceExec('DD specs : movingLimits.rectLim.left = '+this.movingLimits.rectLim.left,1); */
		/* traceExec('DD specs : movingLimits.rectLim.leftSpecs = '+this.movingLimits.rectLim.leftSpecs,1); */
	}
}
// deplacement circonscrit a un rectangle dont les coordonnees sont relatives au parent de l'objet a deplacer in fine'
// --> n?cessite le chargement prealable de ces objets ds la page  (sinon parametrer le DD avec bDynamicsMovingLimits = true)

    if (this.movingLimits.orientation == 'h'){
		this.movingLimits.rectLim.topSpecs = 
		this.movingLimits.rectLim.top = (specs.posRelI ? eval(specs.posRelI.top)
													   : 0) ; 
		this.movingLimits.rectLim.bottomSpecs = 
		this.movingLimits.rectLim.bottom = 
				  _rum.$getHeight(this.specs.oHtmlToMove)
				+ this.movingLimits.rectLim.top;
	}
	else
    if (this.movingLimits.orientation == 'v'){
		this.movingLimits.rectLim.leftSpecs = 
		this.movingLimits.rectLim.left= (specs.posRelI ? eval(specs.posRelI.left)
													   : 0) ;  
		this.movingLimits.rectLim.rightSpecs = 
		this.movingLimits.rectLim.right = 
				  _rum.$getWidth(this.specs.oHtmlToMove);
				+ this.movingLimits.rectLim.left;
	}
	
/*
    // useless sizes  / orientation
    if (this.movingLimits.orientation == 'h'){
//	  if (this.specs.bDynamicsMovingLimits) 
//	      this.movingLimits.rectLim.topSpecs = this.movingLimits.rectLim.bottomSpecs = null;  // top et bottom contraints par orientation + posRelI
//	  else
	      this.movingLimits.rectLim.top   = this.movingLimits.rectLim.bottom = null;  // top et bottom contraints par orientation + posRelI
    }
    else
    if (this.movingLimits.orientation == 'v')
      this.movingLimits.rectLim.left  = this.movingLimits.rectLim.right = null;   // left et right contraints par orientation + posRelI
*/

//define sensitive margin to mouse move for resize
this.specs.sensitiveEdgeWidth = specs.sensitiveEdgeWidth || SENSITIVEEDGEWIDTH_DEFAULT;


  // initial top and left position of object to move (utility ? )
  if (this.specs.posRelI.top != null)
    this.specs.oHtmlToMove.style.top  = this.specs.posRelI.top;
  if (this.specs.posRelI.left != null)
    this.specs.oHtmlToMove.style.left = this.specs.posRelI.left;


/*
this.specs.dropTargets   = (specs.dropTargets != null) ? specs.dropTargets :  false;
// transforme les elts Html en cibles

if (this.specs.dropTargets) {

	var c;
	for (var i = 0; i < this.specs.dropTargets.length; i++)  {
		
	
		c = this.specs.dropTargets[i];
		c.bh_Target = Target;
		c.bh_Target('undef',c);
		
	}
}
*/		
/* traceExec('later end this.movingLimits.bRectLim = '+this.movingLimits.bRectLim,73); */
if (flagModSpecsMovingLimitsRectLim)
	specs.movingLimits.rectLim = null;

}


/*
rialto.widgetBehavior.DragAndDrop 
= function (specs){		
//===============================
//  @param specs : cf. rialto.widgetBehavior.DDStdtLoadParameters


  // to revise (for DD et ReSize 
  // creation de l'attribut de l'oCiu stockant les infos relatives au DD
  if (!this.oCiu) this.oCiu = new Array();
  this.oCiu['DragAndDrop'] = this;

  // load orders of movement and movement limits  if no bDynamicsLimitMoving
  if (!this.oCiu['DragAndDrop'].loadSpecs){
     this.oCiu['DragAndDrop'].loadSpecs = rialto.widgetBehavior.DDStdtLoadParameters;
  }
  this.oCiu['DragAndDrop'].loadSpecs(specs);

  // compute dynamics drag limits 
  if (this.oCiu['DragAndDrop'].specs.bDynamicsMovingLimits) {
      if (!this.oCiu['DragAndDrop'].loadLimitsDyn)
        this.oCiu['DragAndDrop'].loadLimitsDyn = rialto.widgetBehavior.DDStdtLoadLimitsMoving;
      // compute drag limits (see too mouse down handler)
      this.oCiu['DragAndDrop'].loadLimitsDyn();
  }


  // pour W3C Mozilla : DD est enregistr? et donc pris en compte au niveau du document il faut donc marqu?
  // sp?cifiquement les elts Html sensibles au DD
	//          this.dragAndDrop = true;
  // marquage des elts Html poign?es pour le DD, lien entre ces objets et les specs du DD
  // cibles d?sign?es
     var oCiu = this.oCiu['DragAndDrop'];
     for (var i=0; i < oCiu.specs.oHtmlEvtTarget.length; i++) {
         oCiu.specs.oHtmlEvtTarget[i].dragAndDrop = true;
         oCiu.specs.oHtmlEvtTarget[i].refObjSpecs = this;
     }

      // enregistrement comportement DD pour navigateur IE
      //(pas d'utilisation de attachEvent qui rend this indisponible -> utilisation d'1 m?thode maison addHandler)
      if ( typeof document.addEventListener == "undefined"){

             // enregistrement du MDown
             var tOCible =  oCiu.specs.oHtmlEvtTarget;

             for (var i=0; i < tOCible.length; i++) {
               tOCible[i].addHandler = addHandler;
               tOCible[i].methodMouseDown = rialto.widgetBehavior.DragAndDropMouseDownHandler;
               tOCible[i].addHandler(tOCible[i],'onmousedown','methodMouseDown');

               tOCible[i].methodMouseMove = rialto.widgetBehavior.DragAndDropMouseMoveHandler;
               tOCible[i].methodMouseUp   = rialto.widgetBehavior.DragAndDropMouseUpHandler;
               tOCible[i].addHandler(tOCible[i],'onmousemove','methodMouseMove');
               tOCible[i].addHandler(tOCible[i],'onmouseup','methodMouseUp');

               // pour test
               tOCible[i].methodDebDD   = function (){window.status ='debut du d?placement this.id='+this.id;};
               tOCible[i].addHandler(tOCible[i],'onmousedown','methodDebDD');
               tOCible[i].methodFinDD   = function (){window.status ='fin du d?placement';};
               tOCible[i].addHandler(tOCible[i],'onmouseup','methodFinDD');
             }
  }

  // enregistrement W3C
  else{
      if (!document.rialtoEnregtDragAndDrop){
         document.rialtoEnregtDragAndDrop = true;
         document.addEventListener("mousemove",rialto.widgetBehavior.DragAndDropMouseMoveHandler, false);
         document.addEventListener("mouseup",  rialto.widgetBehavior.DragAndDropMouseUpHandler, false);
         document.addEventListener("mousedown",rialto.widgetBehavior.StopSelectDef,false);
         document.addEventListener("mousedown",rialto.widgetBehavior.DragAndDropMouseDownHandler, false);
      }
  }

//  var oHtmlToMove =  this.specs.oHtmlToMove;
  // Preliminary creating of ghost to accelerate the process later
  if (this.specs.ghost){
      var ghostFrame = window.objects ? window.objects['singleGhostFrame']:null; //document.getElementById('cadreghostUnique');
      if (ghostFrame == null) {
		window.objects['singleGhostFrame'] = ghostFrame = document.createElement('DIV');
        ghostFrame.id = 'singleGhostFrame';
        ghostFrame.className = 'ghostDD_' + this.specs.ghost.aspect;
        document.body.appendChild(ghostFrame);
      }
  }

  this.extendToMissile = function (specs) {
	this.$$bh_Missile = Missile;
	this.$$bh_Missile(specs);
  }        



} // constructor end

*/
//-------------  DragAndDrop  ----------------------------------------

rialto.widgetBehavior.constructorDragAndDrop 
= function (specs){		
//===============================
//  @param specs : cf. rialto.widgetBehavior.DDStdtLoadParameters
/* traceExec(' DD constructor specs.bRectLim= '+specs.bRectLim,73); */

  // to revise (for DD et ReSize 
  // creation de l'attribut de l'oCiu stockant les infos relatives au DD
  if (!this.oCiu) this.oCiu = new Array();
  this.oCiu['DragAndDrop'] = this;

  // load orders of movement and movement limits  if no bDynamicsLimitMoving
  if (!this.oCiu['DragAndDrop'].loadSpecs){
     this.oCiu['DragAndDrop'].loadSpecs = rialto.widgetBehavior.DDStdtLoadParameters;
  }
  this.oCiu['DragAndDrop'].loadSpecs(specs);

  // compute dynamics drag limits 
  if (this.oCiu['DragAndDrop'].specs.bDynamicsMovingLimits) {
      if (!this.oCiu['DragAndDrop'].loadLimitsDyn)
        this.oCiu['DragAndDrop'].loadLimitsDyn = rialto.widgetBehavior.DDStdtLoadLimitsMoving;
      // compute drag limits (see too mouse down handler)
traceExec('before call loadLimitsDyn this.movingLimits.bRectLim = '+
this.movingLimits.bRectLim,73);
      this.oCiu['DragAndDrop'].loadLimitsDyn();
  }


  // pour W3C Mozilla : DD est enregistr? et donc pris en compte au niveau du document il faut donc marqu?
  // sp?cifiquement les elts Html sensibles au DD
	//          this.dragAndDrop = true;
  // marquage des elts Html poign?es pour le DD, lien entre ces objets et les specs du DD
  // cibles d?sign?es
     var oCiu = this.oCiu['DragAndDrop'];
     for (var i=0; i < oCiu.specs.oHtmlEvtTarget.length; i++) {
         oCiu.specs.oHtmlEvtTarget[i].dragAndDrop = true;
         oCiu.specs.oHtmlEvtTarget[i].refObjSpecs = this;  //link oHtml --> handler with specs 
		 if (!oCiu.specs.oHtmlEvtTarget[i].behavior) {
		 	oCiu.specs.oHtmlEvtTarget[i].behavior = {};
		 }
		 if (!oCiu.specs.oHtmlEvtTarget[i].behavior['DD'])
		 	oCiu.specs.oHtmlEvtTarget[i].behavior['DD'] = {};
		 oCiu.specs.oHtmlEvtTarget[i].behavior['DD'].running = false;
     }

      // enregistrement comportement DD pour navigateur IE
      //(pas d'utilisation de attachEvent qui rend this indisponible -> utilisation d'1 m?thode maison addHandler)
      if ( typeof document.addEventListener == "undefined"){

             // enregistrement du MDown
             var tOCible =  oCiu.specs.oHtmlEvtTarget;

             for (var i=0; i < tOCible.length; i++) {
               tOCible[i].addHandler = addHandler;
               tOCible[i].methodMouseDown = rialto.widgetBehavior.DragAndDropMouseDownHandler;
               tOCible[i].addHandler(tOCible[i],'onmousedown','methodMouseDown');

               tOCible[i].methodMouseMove = rialto.widgetBehavior.DragAndDropMouseMoveHandler;
               tOCible[i].methodMouseUp   = rialto.widgetBehavior.DragAndDropMouseUpHandler;
               tOCible[i].addHandler(tOCible[i],'onmousemove','methodMouseMove');
               tOCible[i].addHandler(tOCible[i],'onmouseup','methodMouseUp');

               // pour test
               tOCible[i].methodDebDD   = function (){window.status ='debut du d?placement this.id='+this.id;};
               tOCible[i].addHandler(tOCible[i],'onmousedown','methodDebDD');
               tOCible[i].methodFinDD   = function (){window.status ='fin du d?placement';};
               tOCible[i].addHandler(tOCible[i],'onmouseup','methodFinDD');
             }
  }

  // enregistrement W3C
  else{
      if (!document.rialtoEnregtDragAndDrop){
         document.rialtoEnregtDragAndDrop = true;
         document.addEventListener("mousemove",rialto.widgetBehavior.DragAndDropMouseMoveHandler, false);
         document.addEventListener("mouseup",  rialto.widgetBehavior.DragAndDropMouseUpHandler, false);
         document.addEventListener("mousedown",rialto.widgetBehavior.StopSelectDef,false);
         document.addEventListener("mousedown",rialto.widgetBehavior.DragAndDropMouseDownHandler, false);
      }
  }

//  var oHtmlToMove =  this.specs.oHtmlToMove;
  // Preliminary creating of ghost to accelerate the process later
  if (this.specs.ghost){
      var ghostFrame = rialto.session.objects ? rialto.session.objects['singleGhostFrame']:null; //document.getElementById('cadreghostUnique');
      if (ghostFrame == null) {
		rialto.session.objects['singleGhostFrame'] = ghostFrame = document.createElement('DIV');
        ghostFrame.id = 'singleGhostFrame';
        ghostFrame.className = 'ghostDD_' + this.specs.ghost.aspect;
        document.body.appendChild(ghostFrame);
      }
  }

  this.extendToMissile = function (specs) {
	this.$$bh_Missile = Missile;
	this.$$bh_Missile(specs);
  }        



} // constructor end

rialto.widgetBehavior.createBehavior(
	'DragAndDrop',
	rialto.widgetBehavior.constructorDragAndDrop
);

rialto.widgetBehavior.DDtargetOrTargetChild = function (oHtml) {
//-----------------------------------------
    var div= oHtml;
    while (div && !div.dragAndDrop) {
      div = div.parentNode;
    }
    if (div && div.dragAndDrop) {
      return div;
    }  
    else
      return null;
}

// to revise        
rialto.widgetBehavior.DDmodCursor = function (oHtml, direction, orientation, cible){
//-------------------------------------------------------------
///* traceExec('DDmodCurso cible= '+cible+ ' orientation = '+orientation+ ' direction= '+direction+' oHtml.id= '+oHtml.id,1); */
     if (cible){
        oHtml.style.cursor = "move";  // a revoir  pour Moz pour les fenetres
                                      // ne fonctionne pas il doit falloir changer le curseur d'1 autre elt
        return;
     }

     if (direction == ""){
// ne fctionne pas le curseur peut correspondre au passage precdt ds la zone sensible
//                            oHtml.style.cursor = oHtml.svgCursor;
//        oHtml.style.cursor = "default";

//                            oHtml.oCiu['DragAndDrop'].dsChampMm = false;
     }
     else
     if (orientation == 'v')         //oSpecs.movingLimits.
       {oHtml.style.cursor = direction + "-resize";
//                            /* traceExec('DD mm ds champ dir='+direction,76); */
//                            oHtml.oCiu['DragAndDrop'].dsChampMm = true;
     }

     else
     if (orientation == 'h'){
       oHtml.style.cursor = direction + "-resize";
//       /* traceExec('oHtml.style.cursor = '+oHtml.style.cursor,1); */
//                            /* traceExec('DD mm ds champ dir='+direction,76); */
//                            oHtml.oCiu['DragAndDrop'].dsChampMm = true;
     }

     else{
       oHtml.style.cursor = 'move';
                            /* traceExec('DD mm ds champ dir='+direction,1); */
//                            oHtml.oCiu['DragAndDrop'].dsChampMm = true;
     }
}

rialto.widgetBehavior.StopSelectDef = function(e){
//=================================
         stopDefault(e);
}
        
//------------    Missile  ----------------------------------
rialto.widgetBehavior.Missile
= function (specs) {
//================
/*
@domain						: path to define authorized targets (ex. Tree.node)
@targets					: targets array (not yet implemented)
@domainUnauthorizedTarget	: path to define unauthorized targets (ex. Tree.node.leaf)
@targetChoice				: choice  between good targets strategy 
								'' 				: the target above (descendant of, or covered ) is the better
								'firstIsBetter' : the first target finded is the good (faster)
@circularDropAuthorized		: drop on ancestors authorized 
*/
 var domain 						= specs.domainTargets;
 var targets 						= specs.targets;
 var domainUnauthorizedTarget 		= specs.unauthorizedTargets;
 this.specs.targetChoice 			= specs.targetChoice || ''; 

 this.specs.circularDropAuthorized	= specs.circularDropAuthorized || false;
 this.specs.dropTargets = true;

// if (typeof domain == 'string'){
 this.specs.domain = domain; 
 this.specs.targets = targets;

 if (targets != undefined) {
 	if (!this.specs.domain) {
		alert('missile constructeur avec cible mais sans domain defini');
		this.specs.domain = '__domProv'+ rialto.widgetBehavior.Missile.prototype.idDomainProv++;
		alert('domain construit = '+this.specs.domain);
	}	
	for (var i = 0; i < targets.length; i++)  {	
		rialto.widgetBehavior.affect(targets[i],'Target',
									 {domain: this.specs.domain});
	}
	
 }
 
/*
 }
 else if(domain instanceof Array) {
	this.specs.domain = '__domProv'+Missile.prototype.idDomainProv++;
	var c;
	for (var i = 0; i < domain.length; i++)  {	
		c = domain[i];
//		c.bh_Target = Target;
//		c.bh_Target(this.specs.domain,c);	
		rialto.widgetBehavior.affect(c,'Target',{domain: this.specs.domain});
	}
 }
*/ 
// if (unauthorizedTargets != undefined)
 if (typeof domainUnauthorizedTarget == 'string'){
	this.specs.domainUnauthorizedTarget = domainUnauthorizedTarget; 
 }
 else if(domainUnauthorizedTarget instanceof Array) {
	this.specs.domainUnauthorizedTarget = '__domProv'+Missile.prototype.idDomainProv++;
	var c;
	for (var i = 0; i < domainUnauthorizedTarget.length; i++)  {	
		c = domainUnauthorizedTarget[i];
		rialto.widgetBehavior.affect(c,'Target',{domain: this.specs.domainUnauthorizedTarget});
	}
 }
 /* traceExec('Missile id= '+this.id+ ' dom = '+this.specs.domain+' un-Dom= '+this.specs.domainUnauthorizedTarget,73); */
 
 	
/*
var oSpecs
if (!specs) 
	oSpecs = new Object;
else
	oSpecs = specs;	

this.specsMiss = new Object;
// to revise : fixed in target 
this.specsMiss.missileAsOnePixel  = (specs.missileAsOnePixel != 'undefined') ? specs.missileAsOnePixel
											 				 : true;
//_DDMgr.addMissile(this.domain, this.oHtml);
*/
}

rialto.widgetBehavior.Missile.prototype.idDomainProv = 0;

rialto.widgetBehavior.createBehavior(
	'Missile',
	 rialto.widgetBehavior.Missile,
	'DragAndDrop'
);


//-------------   Target -------------------------------------

rialto.widgetBehavior.baseTarget
= function (specs) {
//================
if (specs == undefined) specs = {};
var oHtml  = specs.oHtml;
var domain = specs.domain;

// to revise if multi affect
this.oHtml 	= oHtml  || this;

if (	!this.oHtml.id
	||  ((typeof this.oHtml.id) == 'undefined')){
	this.oHtml.id = rialto.widgetBehavior.baseTarget.prototype.nbInstances++;
}
this.id = this.oHtml.id

//-- setup target :
/*
//soon target behavior
if 	(this.withBehavior['Target']) {
	if (specs.domain != undefined) 
		this.domain = specs.domain;
}
else {
	this.domain = new Array;
	this.domain[this.domain.length] = domain || 'undef'; 
}
*/

this.domain = domain || 'undef'; ;

var oSpecs;
if (!specs) {
	oSpecs = new Object;
	/* traceExec('target new',79); */
}
else 
	oSpecs = specs;	


this.specsTarg = new Object;
this.specsTarg.missileAsOnePixel  = (oSpecs.missileAsOnePixel != undefined) ? 
									oSpecs.missileAsOnePixel
								:	true;
this.specsTarg.borderIsTarget = 	(oSpecs.borderIsTarget    != undefined) ? 
									oSpecs.borderIsTarget
								: 	true;

this.witnessOfDragHover = rialto.widgetBehavior.baseTarget.witnessOfDragHover;

//-- add target in centralized list
_DDMgr.addTarget(this.oHtml, this.domain);
}
rialto.widgetBehavior.baseTarget.prototype.nbInstances = 0;

rialto.widgetBehavior.baseTarget.witnessOfDragHover = function(display, isTargetsUnAuthorized) {
//=================================================
	if (this.witnessDragHover) return;
	
    var iTopLeftBoundDivToMoveInVP = 
  					_rum.$divInternalTopLeftInViewPort(this.oHtml);
  
    var iTopBoundDivToMoveInVP     = iTopLeftBoundDivToMoveInVP.top;
    var iLeftBoundDivToMoveInVP    = iTopLeftBoundDivToMoveInVP.left;
    
	this.witnessDragHover = document.createElement('DIV');
	this.ws = this.witnessDragHover.style;
	if (isTargetsUnAuthorized)
		this.witnessDragHover.className    = 'dashed line redBorder';
	else
		this.witnessDragHover.className    = 'dashed line greenBorder';
	
	document.body.appendChild(this.witnessDragHover);		

	// particular case : invisibility outside body --> paint witness inside 
	if (this.oHtml.nodeName=="BODY") {
		_rum.$setSizeConformW3C(this.witnessDragHover,document.body);
		this.ws.top = this.ws.left = 0;
	}
	
	else
	if (this.specsTarg.borderIsTarget){

		this.ws.width  = _rum.$getWidth(this.oHtml,borderLess=false); //this.oHtml.offsetWidth;
		this.ws.height = _rum.$getHeight(this.oHtml,borderLess=false); //this.oHtml.offsetHeight;
		_rum.$setSizeConformW3C(this.witnessDragHover);
	    this.ws.top	 =  iTopBoundDivToMoveInVP  - _rum.$$getBorderTopWidth(this.oHtml)
	    										- _rum.$$getBorderTopWidth(this.witnessDragHover);   								  				  	
	    this.ws.left =  iLeftBoundDivToMoveInVP - _rum.$$getBorderLeftWidth(this.oHtml) 
	    										- _rum.$$getBorderLeftWidth(this.witnessDragHover);
	}
	else {
		this.ws.width  = _rum.$getWidth(this.oHtml,borderLess=true);
		this.ws.height = _rum.$getHeight(this.oHtml,borderLess=true);
		 //or parseInt(_rum.$getStyle(this.witnessDragHover,'borderTopWidth'));
	    this.ws.top	 =  iTopBoundDivToMoveInVP  - _rum.$$getBorderTopWidth(this.witnessDragHover); 								  				  	
	    this.ws.left =  iLeftBoundDivToMoveInVP - _rum.$$getBorderLeftWidth(this.witnessDragHover);
	}   
	if (display) 
	    this.witnessDragHover.style.display = 'block';
	else
	    this.witnessDragHover.style.display = 'none';
}

rialto.widgetBehavior.baseTarget.prototype.DDHover = function ( missile, isTargetsUnAuthorized) {
//================================================
// default DDHover
// DDHover and DDOuter must be override together
	this.witnessOfDragHover(display=true,isTargetsUnAuthorized);
}
rialto.widgetBehavior.baseTarget.prototype.DDOuter = function ( missile) {
//================================================
// default DDOuter
// DDHover and DDOuter must be override together
	if (this.witnessDragHover) {
		document.body.removeChild(this.witnessDragHover);
		this.witnessDragHover = null;
	}
} 

rialto.widgetBehavior.createBehavior(
	'Target',
	rialto.widgetBehavior.baseTarget	
);

